﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace lcmyjobs.Web.users
{
    public partial class user_search : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txtjob.Attributes.Add("readonly", "true");
                txttrade.Attributes.Add("readonly", "true");
                txtarea.Attributes.Add("readonly", "true");
                
                this.Title = string.Format("人管理中心—职位搜索：职位搜索   {0}", Application["webname"].ToString());
                if (Session["user_id"] != null)
                {
                    int id = int.Parse(Session["user_id"].ToString());
                    this.lblName.Text = Session["user_name"].ToString();
                }
                else
                {
                    Response.Redirect("userlogin.html");
                }
            }

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            StringBuilder url = new StringBuilder("JobList.html");
            url.Append(GetStr());
            Response.Redirect(url.ToString());
        }
        private string GetStr()
        {
            StringBuilder str = new StringBuilder("?");

            int type = 0;
            if (rbtNo.Checked) type = 0;
            if (rbtnew.Checked) type = 2;
            if (rbtold.Checked) type = 1;
            string area = txtarea.Text.Trim();
            string trade = txttrade.Text.Trim();            
            int edu = int.Parse(ddledu.SelectedValue.ToString());           
            int exp = int.Parse(ddlExp.SelectedValue.ToString());            
            int lan = int.Parse(selange.Value.ToString());
            int level = int.Parse(selevel.Value.ToString());
            string rtime = "0";
            string jobs = txtjob.Text.Trim();
            string jobsClass = this.hid_jobclass.Value;
            string jobs_id = "";
            string key_words = this.txt_keywords.Text;
            int min = 0, max = 0;            
            if (txtYmin.Text.Trim() != "")
                min = int.Parse(txtYmin.Text.Trim());
            if (txtYmax.Text.Trim() != "")
                max = int.Parse(txtYmax.Text.Trim());
            string dwgm = ddldwgm.SelectedItem.Text;

            if (!string.IsNullOrEmpty(jobs))
            {
                string[] jobsl = jobs.Split(',');
                string[] jobsClassl = jobsClass.Split(',');
                if (jobsl.Length > 0)
                {
                    for (int i = 0; i < jobsl.Length; i++)
                    {
                        DataSet ds = new lcmyjobs.BLL.jobs().GetList(" job_name = N'" + jobsl[i] + "' AND jobclassname =N'" + jobsClassl[i] + "' ");

                        jobs_id += ds.Tables[0].Rows[0]["jobs_id"].ToString() + ",";
                    }

                    jobs_id.Substring(0, jobs_id.Length - 1);
                }
            }
            str.Append("workerclass=" + type);
            str.Append("&jobsname=" + jobs_id);
            str.Append("&areaname=" + area);
            str.Append("&tradename=" + trade);            
            str.Append("&edu=" + edu);
            str.Append("&exp=" + exp);           
            str.Append("&lan=" + lan);
            str.Append("&level=" + level);           
            str.Append("&key_words=" + key_words);
            str.Append("&min=" + min);
            str.Append("&max=" + max);
            str.Append("&dwgm=" + dwgm); 
            return str.ToString();


        }
    }
}